using System;
using System.Collections.Generic;
using System.IO;

using Atomic.Structures;
using Atomic.Vasp;

namespace Atomic.Samples.Structures
{
	public static class Degeneracies
	{
		public static void Sample1()
		{
			// Build conventional fcc cell, with oxygen or vacancy at interstitial sites (represented as a PlaceholderAtom object).
			Structure lattice = StructureHelper.CreateConventionalFaceCenteredCubicStructureOctahedral(4.6, Atom.Ni, Atom.Placeholder(Atom.O, Atom.Vacancy));

			// Fill the placeholders (oxygen or vacancy) in every possible way using ATAT's genstr tool.
			// Show all symmetrically distinct structures using VESTA. Comment out if not required.
			Structure.Show(lattice.FillPlaceholdersCombinatorialReduced());

			// Do the same using a different method using the symspg library where degeneracies are counted.
			foreach (StructureDegeneracy d in StructureDegeneracyGenerator.GenerateDegeneracies(lattice))
			{
				// Remove vacancies from the generated structure.
				Structure structure = d.Structure.RemoveVacancies();
				int degeneracy = d.Degeneracy;

				// Formula for the file name. Remove vacancies (Vac) from the file name.
				string formula = structure.BuildFormula(Atom.Ni, Atom.O);

				// Print formula and degeneracy.
				Console.WriteLine("{0} {1}", formula, degeneracy);

				// Write structure to a file in VASP POSCAR format.
				VaspPoscar.Write(structure, new FileInfo("/tmp/POSCAR_" + formula));
			}
		}
	}
}
